package com.eight.controller;

import com.eight.util.WebFileUtil;
import com.eight.vo.ComResult;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description: TODO
 * @Author: Van.Planifolia
 * @CreateTime: 2023-02-28  10:42
 * @Version: 1.0
 */
@RestController
public class OssFileController {
    /**
     * 图片上传的Controller
     *
     * @param file    MultipartFile前端传入
     * @param dirPath 保存路径
     * @return 上传结果
     */
    @ResponseBody
    @RequestMapping(value = "/upload/ossfile/{dirPath}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ComResult upload(@RequestPart(value = "file") MultipartFile file, @PathVariable(value = "dirPath") String dirPath) {
        String path = WebFileUtil.remotelyUpLoad(file, dirPath);
        return new ComResult(2000, "上传成功", path);
    }
}
